(function () {
	interface IRes<TData = unknown> {
		code: number;
		error?: string;
		data: TData;
	}
	interface IUserProfileRes {
		name: string;
		homepage: string;
		avatar: string;
	}

	function fetchUserProfile(): Promise<IRes<IUserProfileRes>> {
		let data: IUserProfileRes = {
			name: 'lys',
			homepage: '1',
			avatar: 'http:www.bai.com',
		};

		return Promise.resolve({
			code: 10000,
			data: {
				name: 'lys',
				homepage: '1',
				avatar: 'http:www.bai.com',
			},
		});
	}

	fetchUserProfile().then((res) => {
		console.log('res1___', res);
	});
	interface IPaginationRes<TItem = unknown> {
		data: TItem[];
		page: number;
		totalCount: number;
		hasNextPage: boolean;
	}

	//而泛型嵌套的场景也非常常用，比如对存在分页结构的数据，我们也可以将其分页的响应结构抽离出来：
	function fetchUserProfileList(): Promise<IRes<IPaginationRes<IUserProfileRes>>> {
		return Promise.resolve({
			code: 10000,
			data: {
				data: [
					{ name: 'lys', homepage: '1', avatar: 'http:www.bai.com' },
					{ name: 'zzz', homepage: '2', avatar: 'http:www.bai.com' },
				],
				page: 1,
				totalCount: 3,
				hasNextPage: true,
			},
		});
	}
	fetchUserProfileList().then((res2) => {
		console.log('res2___', res2);
	});
})();
